import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

import xxl from './xxl'
import cj from './cj'

import tcj from './tcj.js'

Vue.use(VueRouter)

const routes = [

  ...cj,
  {
    path: '/',
    alias: 'home',
    name: 'Home',
    component: Home
  },
  ...xxl,
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },

  ...tcj,
  // {
  //   path: '/',
  //   name: 'Home',
  //   component: Home
  // },
  // {
  //   path: '/about',
  //   name: 'About',
  //   component: () => import('../views/About.vue')
  // },

]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  // console.log(to,from,next);
 next()
})
 
router.beforeEach((to,from,next)=>{
  if(to.path.includes('/shoppingcar')){
    if(localStorage.userInfo){
      next()
    }else{
      next({
        path:'/login',
        query:{
          target:to.path
        }
      })
    }
  }else{
    next()
  }
})
export default router
